package com.rill.action;

import java.util.Date;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.rill.po.Article;
import com.rill.service.ArticleService;

/**添加文章
 */
public class AddArticleAction extends ActionSupport {
	//service支持
	private ArticleService articleService;
	//封装表单参数
	private String title;//表单中name的封装
	private String content;


	public ArticleService getArticleService() {
		return articleService;
	}


	public void setArticleService(ArticleService articleService) {
		this.articleService = articleService;
	}


	public String getTitle() {
		return title;
	}


	public void setTitle(String title) {
		this.title = title;
	}


	public String getContent() {
		return content;
	}


	public void setContent(String content) {
		this.content = content;
	}

	@Override
	public String execute() throws Exception {
		//动态获取username
		Map session = ActionContext.getContext().getSession();//放到session中
		String username = (String) session.get("username");
		Article article = new Article();//封装po
		article.setContent(content);
		article.setTitle(title);
		article.setDate(new Date());
		article.setUsername(username);
		
		//设置点击量初始为0
		article.setHasread(0);
		articleService.addArticle(article);
		return SUCCESS;
	}

}
